/**
 * Created with IntelliJ IDEA.
 * User: ajhin
 * Date: 4/3/14
 * Time: 10:10 PM
 * To change this template use File | Settings | File Templates.
 */
package com.societyGames.flashForms
{
import com.societyGames.system.EventObject;

import flash.events.Event;

/**
 * Passes width and height to child. If child changes size on its own or the container changes size
 * raises a sizeChanged event.
 */
public class ChangeSizeContainer extends SingleItemContainer implements IChangeSize
{
  private var _sizeChangedEventObject:EventObject;

  public function ChangeSizeContainer()
  {
    _sizeChangedEventObject = new EventObject(this, "SIZE_CHANGED", Event);
  }

  public function get sizeChangedEventObject():EventObject
  {
    return _sizeChangedEventObject;
  }

  override public function set width(value:Number):void
  {
    if (this._item != null && this._item.width != value)
    {
      this._item.width = value;
      this._sizeChangedEventObject.dispatchEvent();
    }
  }

  override public function set height(value:Number):void
  {
    if (this._item != null && this._item.height != value)
    {
      this._item.height = value;
      this._sizeChangedEventObject.dispatchEvent();
    }
  }

  override protected function childSizeChangedHandler(event:Event):void
  {
    this._sizeChangedEventObject.dispatchEvent();
  }
}
}
